package com.demo.controller;

import com.demo.entity.User;
import com.demo.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class TestController {

    @Autowired
    UserMapper userMapper;

    @GetMapping("/batchInsert")
    public int batchInsert()  {
        List<User> list = new ArrayList<>();
        User user = new User();
        user.setUserName("张三");
        list.add(user);

        user = new User();
        user.setUserName("李四");
        list.add(user);

        user = new User();
        user.setUserName("王五");
        list.add(user);
        return userMapper.insertList(list);
    }

    @GetMapping("/insert")
    public String insert()  {
        User user = new User();
        user.setUserName("张三");
        userMapper.insert(user);
        return "插入成功";
    }
}
